package com.hzsai.kafka;
//
//import org.apache.kafka.clients.producer.Producer;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.autoconfigure.kafka.ConcurrentKafkaListenerContainerFactoryConfigurer;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
//import org.springframework.kafka.core.*;
//import org.springframework.kafka.listener.DeadLetterPublishingRecoverer;
//import org.springframework.kafka.listener.SeekToCurrentErrorHandler;
//import org.springframework.util.backoff.FixedBackOff;
//
///**
// * @author: hzsai
// * @date : 2020/3/25
// * usage:
// **/
//@Configuration
//public class KafkaProducerConfiguration {
//
//    @Autowired
//    private KafkaTemplate<String, String> kafkaTemplate;
//
//    private KafkaTemplate<String, String> defaultKafkaTemplate() {
//        KafkaTemplate<String, String> template = new KafkaTemplate<String, String>();
//    }
//
//    @Bean
//    public KafkaSender kafkaSender() {
//        return new KafkaSender(kafkaTemplate);
//    };
//
//    @Bean
//    public ConcurrentKafkaListenerContainerFactory<String, String> kafkaListenerContainerFactory(
//            ConcurrentKafkaListenerContainerFactoryConfigurer configurer,
//            ConsumerFactory<String, String> kafkaConsumerFactory,
//            KafkaTemplate<String, String> template) {
//        ConcurrentKafkaListenerContainerFactory<Object, Object> factory =
//                new ConcurrentKafkaListenerContainerFactory<>();
//        configurer.configure(factory, kafkaConsumerFactory);
//        // 3秒尝试间隔，3次最大尝试
//        factory.setErrorHandler(new SeekToCurrentErrorHandler(
//                new DeadLetterPublishingRecoverer(template), new FixedBackOff(3000L, 3)));
//        return factory;
//    }
//
//    @Bean
//    public ConsumerFactory<String, String> consumerFactory() {
//        return new DefaultKafkaConsumerFactory<String, String>();
//    }
//
//    @Bean
//    public ProducerFactory<String, String> producerFactory() {
//        return new DefaultKafkaProducerFactory<String, String>();
//    }
//}
